<?php
class GmBatchVo extends SzAbstractMySqlVo
{

    private $batchId;
    private $listId;
    private $name;
    private $comment;
    private $giftType;
    private $createTime;
    private $expiryTime;
    private $items;
    private $usable;
    private $count;
    private $usedCount;

    /**
     * Initialize GmBatchVo.
     *
     * @param $batchId
     * @param $listId
     * @param $name
     * @param $comment
     * @param $giftType
     * @param $createTime
     * @param $expiryTime
     * @param $items
     * @param $usable
     * @param $count
     * @param $usedCount
     * @param boolean $isInsert default false, means for now this vo is initialized not for insert process
     * @return GmBatchVo
     */
    public function __construct($batchId, $listId, $name, $comment, $giftType, $createTime, $expiryTime, $items, $usable, $count, $usedCount, $isInsert = false) {
        $this->batchId = $batchId;
        $this->listId = $listId;
        $this->name = $name;
        $this->comment = $comment;
        $this->giftType = $giftType;
        $this->createTime = $createTime;
        $this->expiryTime = $expiryTime;
        $this->items = json_decode($items, true);
        $this->usable = $usable;
        $this->count = $count;
        $this->usedCount = $usedCount;

        $this->isInsert = $isInsert;
        $this->voClassName = 'GmBatchVo';
        $this->ormName = 'GmBatch';
    }

    /**
     * @see SzAbstractVo::toArray
     */
    public function toArray($needEncode = false)
    {
        return array(
            'batchId' => $this->getBatchId(),
            'listId' => $this->getListId(),
            'name' => $this->getName(),
            'comment' => $this->getComment(),
            'giftType' => $this->getGiftType(),
            'createTime' => $this->getCreateTime(),
            'expiryTime' => $this->getExpiryTime(),
            'items' => ($needEncode) ? $this->getItems() : $this->getRawItems(),
            'usable' => $this->getUsable(),
            'count' => $this->getCount(),
            'usedCount' => $this->getUsedCount(),
        );
    }

    /**
     * @see SzAbstractVo::toEntireArray
     */
    public function toEntireArray($needEncode = false)
    {
        return array(
            'batchId' => $this->getBatchId(),
            'listId' => $this->getListId(),
            'name' => $this->getName(),
            'comment' => $this->getComment(),
            'giftType' => $this->getGiftType(),
            'createTime' => $this->getCreateTime(),
            'expiryTime' => $this->getExpiryTime(),
            'items' => ($needEncode) ? $this->getItems() : $this->getRawItems(),
            'usable' => $this->getUsable(),
            'count' => $this->getCount(),
            'usedCount' => $this->getUsedCount(),
        );
    }

    /**
     * @see SzAbstractVo::toPureArray
     */
    public function toPureArray()
    {
        return array(
            $this->getBatchId(),
            $this->getListId(),
            $this->getName(),
            $this->getComment(),
            $this->getGiftType(),
            $this->getCreateTime(),
            $this->getExpiryTime(),
            $this->getItems(),
            $this->getUsable(),
            $this->getCount(),
            $this->getUsedCount(),
        );
    }

    public function getBatchId()
    {
        return $this->batchId;
    }

    public function setBatchId($val)
    {
        $this->saveColumnStatus(0, $this->batchId);
        $this->batchId = $val;
    }

    public function getListId()
    {
        return $this->listId;
    }

    public function setListId($val)
    {
        $this->saveColumnStatus(1, $this->listId);
        $this->listId = $val;
    }

    public function getName()
    {
        return $this->name;
    }

    public function setName($val)
    {
        $this->saveColumnStatus(2, $this->name);
        $this->name = $val;
    }

    public function getComment()
    {
        return $this->comment;
    }

    public function setComment($val)
    {
        $this->saveColumnStatus(3, $this->comment);
        $this->comment = $val;
    }

    public function getGiftType()
    {
        return $this->giftType;
    }

    public function setGiftType($val)
    {
        $this->saveColumnStatus(4, $this->giftType);
        $this->giftType = $val;
    }

    public function getCreateTime()
    {
        return $this->createTime;
    }

    public function setCreateTime($val)
    {
        $this->saveColumnStatus(5, $this->createTime);
        $this->createTime = $val;
    }

    public function getExpiryTime()
    {
        return $this->expiryTime;
    }

    public function setExpiryTime($val)
    {
        $this->saveColumnStatus(6, $this->expiryTime);
        $this->expiryTime = $val;
    }

    public function getItems()
    {
        return json_encode($this->items);
    }

    public function getRawItems()
    {
        return $this->items;
    }

    public function setItems($val)
    {
        $encodedLength = SzUtility::strLen(json_encode($val));
        if ($encodedLength > 21840) {
            SzLogger::get()->error('[GmBatchVo] The length of column items exceed the limit, length / limit: ' . $encodedLength . ' / 21840');
            throw new SzException(10522, array('GmBatchVo', '21840', $encodedLength));
        } else if ($encodedLength > 19656) {
            SzLogger::get()->warn('[GmBatchVo] The length of column items exceed the warning level, length / limit: ' . $encodedLength . ' / 21840');
        }
        $this->saveColumnStatus(7, $this->items);
        $this->items = $val;
    }

    public function getUsable()
    {
        return $this->usable;
    }

    public function setUsable($val)
    {
        $this->saveColumnStatus(8, $this->usable);
        $this->usable = $val;
    }

    public function getCount()
    {
        return $this->count;
    }

    public function setCount($val)
    {
        $this->saveColumnStatus(9, $this->count);
        $this->count = $val;
    }

    public function getUsedCount()
    {
        return $this->usedCount;
    }

    public function setUsedCount($val)
    {
        $this->saveColumnStatus(10, $this->usedCount);
        $this->usedCount = $val;
    }

}